﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace EditUsers_Better
{
    internal class TaskService : ITaskService
    {
        // Implement as singleton
        private static TaskService _instance;
        public static TaskService Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new TaskService();
                }
                return _instance;
            }
        }

        private TaskService()
        {
            this.Tasks = new Dictionary<string, TaskDetail>();
        }

        #region ITaskService Members

        public Dictionary<string, TaskDetail> Tasks { get; private set; }

        public void Register(string taskName, IView view, Icon icon)
        {
            // Store as a named task an icon and a view instance.
            TaskDetail taskDetail = 
                new TaskDetail { Icon = icon, View = view };
            Tasks.Add(taskName, taskDetail);
        }

        public void Execute(string taskName)
        {
			if (!Tasks.ContainsKey(taskName))
				return;

            // Execute the ShowDialog method for the IView
            Tasks[taskName].View.ShowDialog();
        }

        #endregion
    }
}
